package pl.polsl.pum2.pj;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class MenuActivity extends Activity {

  private final int MIN_RUBIKS_SIZE = 2;
  private final int MAX_RUBIKS_SIZE = 7;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.menu);

    final CheckBox checkbox = (CheckBox) findViewById(R.id.checkBox1);
    checkbox.setChecked(true);

    final TextView textView = (TextView) findViewById(R.id.textView1);

    final SeekBar seekbar = (SeekBar) findViewById(R.id.seekBar1);
    seekbar.setMax(MAX_RUBIKS_SIZE - MIN_RUBIKS_SIZE);
    seekbar.setProgress(1);
    seekbar.setPadding(30, 0, 30, 0);
    textView.setText(getString(R.string.sizeSelector) + (seekbar.getProgress() + MIN_RUBIKS_SIZE));
    seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
      @Override
      public void onStopTrackingTouch(SeekBar seekBar) {}

      @Override
      public void onStartTrackingTouch(SeekBar seekBar) {}

      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        textView.setText(getString(R.string.sizeSelector) + (progress + MIN_RUBIKS_SIZE));
      }
    });
    
    final SeekBar seekbar2 = (SeekBar) findViewById(R.id.seekBar2);
    seekbar2.setMax(9);
    seekbar2.setProgress(3);
    seekbar2.setPadding(30, 0, 30, 0);
    
    // Watch for button clicks.
    Button goButton = (Button) findViewById(R.id.rubikStart);
    goButton.setPadding(30, 0, 30, 0);
    goButton.setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        // Here we start the next activity, and then call finish()
        // so that our own will stop running and be removed from the
        // history stack.
        Intent intent = new Intent();
        intent.setClass(MenuActivity.this, RubikActivity.class);
        intent.putExtra("rubik-size", seekbar.getProgress() + MIN_RUBIKS_SIZE);
        intent.putExtra("rubik-shuffle", checkbox.isChecked());
        intent.putExtra("sensitivity", (seekbar2.getProgress() + 1)/ 10000f);
        startActivity(intent);
      }
    });

  }

}
